package com.example.myapplicationhjw.demo

fun main(){
//self("HJW","上海")
//    printAll("HJW", "上海", "北京", "广州")
    val res= caculate(10,20){a,b->a+b}
    println(res)
    val res1= caculate(10,20){a,b->a*b}
    println(res1)
}

fun caculate(a: Int,b: Int,op: (Int,Int)->Int): Int{
    return op(a,b)
}



//1.基本函数
fun add(a:Int,b:Int): Int{
    return a+b
}
//2.函数表达式
fun add2(a:Int,b:Int) = a+b

//3.默认参数
fun self(name:String,city:String="上海"){
println("我的姓名是:$name,来自:$city")
}

//4.可变参数(类似于剩余参数)
fun printAll(info:String,vararg msg:String){
println("info的内容为:$info")
    for (m in msg) println(m)
}